<!--
* @description:承运合同管理
* @fileName: NewTransportContract
* @author:石锦涛
* @date:2022-01-08
* @后台人员:石锦涛
-->
<template>
  <div>
    <!-- 新增承运合同 -->
    <el-row :span="1">
      <el-col :span="3">合同标题:</el-col>
      <el-col :span="7"
        ><el-input v-model="jieshu.TheContractTitlec"></el-input
      ></el-col>
      <el-col :span="3">承运单位:</el-col>
      <el-col :span="7"
        ><el-input v-model="jieshu.TheCarrierUnitc"></el-input
      ></el-col>
    </el-row>
    <br />
    <el-row :span="1">
      <el-col :span="3">承运负责人:</el-col>
      <el-col :span="7"
        ><el-input v-model="jieshu.TheCarrierHeadc"></el-input
      ></el-col>
      <el-col :span="3">线路:</el-col>
      <el-col :span="7">
        <el-select v-model="jieshu.Linec" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.LineName"
            :value="item.Id"
          >
          </el-option>
        </el-select>
      </el-col>
    </el-row>
    <br />
    <el-row :span="1">
      <el-col :span="3">吨运价:</el-col>
      <el-col :span="7"
        ><el-input v-model="jieshu.TonsOfFreightc"></el-input
      ></el-col>
      <el-col :span="3">包车条件吨位:</el-col>
      <el-col :span="7"
        ><el-input v-model="jieshu.ConditionTonnagec"></el-input
      ></el-col>
    </el-row>
    <br />
    <el-row :span="1">
      <el-col :span="3">包车金额:</el-col>
      <el-col :span="7"
        ><el-input v-model="jieshu.CharterValuec"></el-input
      ></el-col>
      <el-col :span="3">经办人:</el-col>
      <el-col :span="7"><el-input v-model="jieshu.Agentc"></el-input></el-col>
    </el-row>
    <br />
    <el-row :span="1">
      <el-col :span="3">签订时间:</el-col>
      <el-col :span="7"
        ><el-input type="date" v-model="jieshu.SignedTimec"></el-input
      ></el-col>
      <el-col :span="3">合同金额:</el-col>
      <el-col :span="7"
        ><el-input v-model="jieshu.TheContractAmountc"></el-input
      ></el-col>
    </el-row>
    <br />
    <el-row :span="1">
      <el-col :span="3">合同标的或项目说明:</el-col>
      <el-col :span="12"
        ><el-input
          type="textarea"
          :rows="5"
          placeholder="请输入内容"
          v-model="jieshu.ProjectDescriptioc"
        >
        </el-input
      ></el-col>
    </el-row>
    <br />
    <el-row :span="1">
      <el-col :span="3">合同主要条款/变更条款:</el-col>
      <el-col :span="12"
        ><el-input
          type="textarea"
          :rows="5"
          placeholder="请输入内容"
          v-model="jieshu.ChangeTheTermsc"
        >
        </el-input
      ></el-col>
    </el-row>
    <br />
    <el-row :span="1">
      <el-col :span="3">合同文本(附件):</el-col>
      <el-col :span="12">
        <el-upload
          class="upload-demo"
          :on-success="upchuan"
          action="https://localhost:44399/api/app/file-common-app/uplosdqiniu"
        >
          <el-button size="small" type="primary">点击上传</el-button>
          <div slot="tip" class="el-upload__tip">
            
          </div>
        </el-upload>
      </el-col>
    </el-row>
    <br />
    <el-row :span="1">
      <el-col :span="3"><el-button @click="Ti()">提交审批</el-button></el-col>
      <el-col :span="1"><el-button @click="fanhui()">取消</el-button></el-col>
      <el-col :span="3"
        ><el-button @click="addjiashu()">保存草稿</el-button></el-col
      >
    </el-row>
  </div>
</template>

<script>
export default {
  data() {
    return {
      jieshu: {
        TheCarContractNOc: "",
        TheContractTitlec: "",
        TheCarrierUnitc: "",
        TheCarrierHeadc: "",
        Linec: "",
        TonsOfFreightc: "",
        ConditionTonnagec: "",
        CharterValuec: "",
        Agentc: "",
        SignedTimec: "",
        TheContractAmountc: "",
        ProjectDescriptioc: "",
        ChangeTheTermsc: "",
        ContractTheTextc: "-",
        ContractStatesc: "0",
        TheApproverc: "-",
        IsDelete: "0",
      },
      options: [],
    };
  },
  methods: {
    //显示线路
    xianlu() {
      this.$axios
        .get("https://localhost:44399/api/app/line-app/page")
        .then((res) => {
          this.options = res.data;
        });
    },
    //添加草稿
    addjiashu() {
      if (this.jieshu.TheContractTitlec.length === 0) {
        alert("标题不能为空");
        return;
      }
      if (this.jieshu.TheCarrierUnitc.length === 0) {
        alert("承运单位不能为空");
        return;
      }
      if (this.jieshu.TheCarrierHeadc.length === 0) {
        alert("承运负责人不能为空");
        return;
      }
      if (this.jieshu.Linec.length === 0) {
        alert("线路不能为空");
        return;
      }
      if (this.jieshu.TonsOfFreightc.length === 0) {
        alert("吨运价不能为空");
        return;
      }
      var retNum = /^\d+(\.\d+)?$/; //匹配数字匹配数字(包括小数)/^\d*$/
      if (!retNum.test(this.jieshu.TonsOfFreightc)) {
        alert("吨运价只能是正数,整数,小数");
        return;
      }
      if (this.jieshu.ConditionTonnagec.length === 0) {
        alert("包车条件不能为空");
        return;
      }
      if (this.jieshu.CharterValuec.length === 0) {
        alert("包车金额不能为空");
        return;
      }
      if (!retNum.test(this.jieshu.CharterValuec)) {
        alert("包车金额只能是正数,整数,小数");
        return;
      }
      if (this.jieshu.Agentc.length === 0) {
        alert("经办人不能为空");
        return;
      }
      if (this.jieshu.SignedTimec.length === 0) {
        alert("签订时间不能为空");
        return;
      }
      if (this.jieshu.TheContractAmountc.length === 0) {
        alert("合同金额不能为空");
        return;
      }
      if (!retNum.test(this.jieshu.TheContractAmountc)) {
        alert("合同金额只能是正数,整数,小数");
        return;
      }
      if (this.jieshu.ProjectDescriptioc.length === 0) {
        alert("合同标的或项目说明不能为空");
        return;
      }
      if (this.jieshu.ChangeTheTermsc.length === 0) {
        alert("合同主要条款/变更条款不能为空");
        return;
      }
      this.$axios
        .post(
          "https://localhost:44399/api/app/new-tran-app/new-transport",
          this.jieshu
        )
        .then((res) => {
          if (res.data.Code > 0) {
            alert("添加成功");
            this.$router.push("/TransportContractManagement");
          } else {
            alert("添加失败");
          }
        });
    },
    //上传
    upchuan(res) {
      if (res != null) {
        this.$message.success("上传文件成功");
        this.jieshu.ContractTheTextc = res;
      } else {
        this.$message.success("上传文件失败");
      }
    },
    //返回管理
    fanhui() {
      this.$router.push("/TransportContractManagement");
    },
    Ti(){
      let loginid=sessionStorage.getItem("Id");
      let loginname=sessionStorage.getItem("Account");
      this.$axios.post("https://localhost:44399/api/app/transport-contract-shen/add-transport-contract?loginname="+loginname+"&loginid="+loginid+"",this.jieshu).then(res=>{
        if(res.data>0)
        {
          this.$message.success("提交成功");
        }
        else
        {
          this.$message.error("提交失败");
        }
      })
    }
  },
  created() {
    this.xianlu();
  },
};
</script>

<style>
</style>